//
//  NCChatUserInfoManager.m
//  AGEmojiKeyboard
//
//  Created by LINAICAI on 2018/4/19.
//

#import "NCChatUserInfoManager.h"
@interface NCChatUserInfoManager()
@property (nonatomic , strong)NSMutableArray<NCChatUser*> *cacheUsers;
@end
@implementation NCChatUserInfoManager
+ (instancetype)shared{
    static NCChatUserInfoManager *manager = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        manager = [[super alloc]init];
    });
    return manager;
}
- (NSMutableArray<NCChatUser*> *)cacheUsers{
    if (!_cacheUsers) {
        _cacheUsers = [NSMutableArray<NCChatUser*> new];
    }
    return _cacheUsers;
}
///更新用户缓存
- (void)refreshUserInfoCache:(NCChatUser *)userInfo{
    [self.cacheUsers addObject:userInfo];
    
}
///获取缓存的用户信息
- (NCChatUser *)getUserCache:(NSString *)senderId{
    for (NCChatUser *user in self.cacheUsers) {
        if ([user.userId isEqualToString:senderId]) {
            return user;
        }
    }
    return nil;
}
///清空用户信息缓存
- (void)clearUserInfoCache{
    [self.cacheUsers removeAllObjects];
}
@end
